package com.xiaoma.vpa;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

import com.xiaoma.drools.DroolsStateSession;
import com.xiaoma.thread.TaskDispatch;

import ch.qos.logback.classic.android.BasicLogcatConfigurator;


/**
 * Example showing loading a KieContainer with drools-compiler dependency.
 */
public class MainActivity extends Activity implements View.OnClickListener {
    private static final TaskDispatch TASK_DISPATCH = TaskDispatch.get();

    DroolsStateSession droolsStateSession;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        BasicLogcatConfigurator.configureDefaultContext();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        droolsStateSession = new DroolsStateSession(this);
        findViewById(R.id.stateful_btn).setOnClickListener(this);
        findViewById(R.id.stateless_btn).setOnClickListener(this);
        findViewById(R.id.multi_stateful_btn).setOnClickListener(this);
        findViewById(R.id.btn_test_vdata_input).setOnClickListener(this);
        findViewById(R.id.btn_clear_packages).setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.stateful_btn:
                TASK_DISPATCH.execute(() -> droolsStateSession.stateFulSession());
                break;
            case R.id.stateless_btn:
                TASK_DISPATCH.execute(() -> droolsStateSession.stateLessSession());
                break;
            case R.id.multi_stateful_btn:
                TASK_DISPATCH.execute(() -> droolsStateSession.multiDrl());
                break;
            case R.id.btn_test_vdata_input:
                TASK_DISPATCH.execute(() -> droolsStateSession.testVDataInput());
                break;
            case R.id.btn_clear_packages:
                TASK_DISPATCH.execute(() -> droolsStateSession.clearAllPackage());
                break;
        }
    }
}